package atguigu.quartz;

import lombok.extern.slf4j.Slf4j;
import org.quartz.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

// 自定义一个任务
@Slf4j
@PersistJobDataAfterExecution
public class TestJob3 implements Job {
    private Integer executeCount = 0;

    public void setExecuteCount(Integer executeCount) {
        this.executeCount = executeCount;
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        String data = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        log.info("execute count: {}, current time: {}",++executeCount, data);
        // 将累加的 count 存入JobDataMap中
        jobExecutionContext.getJobDetail().getJobDataMap().put("executeCount", executeCount);
    }
}